#include "../include/TcpServer.h"

namespace myNameSpace {
TcpServer::TcpServer(unsigned short port, const string &ip): _acceptor(port, ip), _eventLoop(_acceptor) {}

void TcpServer::setAllCallbacks(TcpConnectionCallback &&onNewConnection, TcpConnectionCallback &&onMessage, TcpConnectionCallback &&onClose) {
    _eventLoop.setNewConnectionCallback(std::move(onNewConnection));
    _eventLoop.setMessageCallback(std::move(onMessage));
    _eventLoop.setCloseCallback(std::move(onClose));
}

void TcpServer::start() {
    _acceptor.ready();
    _eventLoop.loop();
}

void TcpServer::stop() {
    _eventLoop.unloop();
}
} // end of namespace myNameSpace
